import { Component, Injector, ViewEncapsulation, ViewChild, ElementRef, OnInit } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { ManHourServiceProxy, BatchManHourListDto, ComboboxItemDto, CostRecordServiceProxy, YclCostListDto} from '@shared/service-proxies/service-proxies';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { Table } from 'primeng/components/table/table';
import { Paginator } from 'primeng/components/paginator/paginator';
import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent';
import { AppWorkshop } from '@shared/AppEnums';

@Component({
    templateUrl: './ycl-record.component.html',
    encapsulation: ViewEncapsulation.None,
    animations: [appModuleAnimation()]
})
export class YclRecordComponent extends AppComponentBase implements OnInit {
    @ViewChild('dataTable') dataTable: Table;
    @ViewChild('paginator') paginator: Paginator;
    //@ViewChild('putIntoProductionModal') putIntoProductionModal: PutIntoProductionModalComponent;

    advancedFiltersAreShown = false;
    anyncing = false;
    //Filters
    filterText = '';

    priority: number = undefined;
    selectedDate = new Date();
    constructor(injector: Injector, private _recordServiceProxy: CostRecordServiceProxy) {
        super(injector);
    }

    ngOnInit() {
        this.selectedDate = new Date();
    }

    getData(event?: LazyLoadEvent) {
        if (this.primengTableHelper.shouldResetPaging(event)) {
            this.paginator.changePage(0);

            return;
        }

        this.primengTableHelper.showLoadingIndicator();

        this._recordServiceProxy
            .getYclReCords(
                this.selectedDate.getFullYear(),
                this.selectedDate.getMonth() + 1,
                undefined,
                this.filterText,
                this.primengTableHelper.getSorting(this.dataTable),
                this.primengTableHelper.getMaxResultCount(this.paginator, event),
                this.primengTableHelper.getSkipCount(this.paginator, event)
            )
            .subscribe(result => {
                this.primengTableHelper.totalRecordsCount = result.totalCount;
                this.primengTableHelper.records = result.items;
                console.log(result.items)
                this.primengTableHelper.hideLoadingIndicator();
            });
    }
}
